const request = require("request");

/** 发起post请求 */
const post = function (url, body, callBack) {
    request({
        url: url,
        method: 'POST',
        headers: {
            "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
        },
        body: body
    }, function resHandler(err, res, body) {
        if (err) {
            callBack(err, null);
            return;
        }

        if (res.statusCode === 200) {
            callBack(err, body);
        } else {
            callBack(new Error('request fail! res.statusCode: ' + res.statusCode), null);
        }
    });
};

module.exports = {
    post: post,
}